<template>
	<el-container>
		<el-aside width="200px" v-loading="showGrouploading">
			<el-container>
				<el-header>
					<el-input placeholder="输入关键字进行过滤" v-model="groupFilterText" clearable></el-input>
				</el-header>
				<el-main class="nopadding">
					<el-tree ref="fixedSort" class="menu" node-key="sortId" :data="fixedSortList" :props="groupsProps" :current-node-key="''" :highlight-current="true" :expand-on-click-node="false"
							 :filter-node-method="groupFilterNode" @node-click="groupClick">
						<template #default="{node, data}">
							<span class="custom-tree-node">
								<span class="label">{{ node.label }}</span>
								<span class="code">{{ data.code }}</span>
							</span>
						</template>
					</el-tree>
				</el-main>
			</el-container>
		</el-aside>
		<el-container>
			<el-header style="height: auto;">
				<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
			</el-header>
			<el-header>
				<div class="left-panel">
				</div>
				<div class="right-panel">
					<el-form-item label="申请人" style="padding-top: 20px;">
						<select-dept-dialog v-model:deptId="search.deptId" :mode="false"/>
					</el-form-item>
					<div class="right-panel-search">
						<el-input v-model="search.keyword" placeholder="名称 / 编号" clearable></el-input>
						<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
					</div>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable ref="table" :apiObj="apiObj" row-key="recordId" stripe remoteSort>
					<el-table-column label="#" type="index" width="50"></el-table-column>
					<el-table-column label="资产编号" prop="assetsCode" width="100" sortable='custom'></el-table-column>
					<el-table-column label="资产名称" prop="assetsName" width="200" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column label="原使用部门" prop="oldOwnDeptName" width="100" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column label="调拨部门" prop="newOwnDeptName" width="100" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column label="资产分类" prop="sortName" width="100" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column label="品牌" prop="brand" width="150" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column label="规格型号" prop="model" width="200" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column label="当前状态" prop="status" width="100">
						<template #default="scope">
							<el-tag type="success" effect="dark" v-if="scope.row.status=='0'">空闲中</el-tag>
							<el-tag type="warning" effect="dark" v-else-if="scope.row.status=='1'">使用中</el-tag>
							<el-tag type="danger" effect="dark" v-else-if="scope.row.status=='2'">维修中</el-tag>
							<el-tag type="info" effect="dark" v-else-if="scope.row.status=='3'">已报废</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="调拨时间" prop="createTime" width="150"></el-table-column>
					<el-table-column label="备注" prop="remark" width="300" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column label="操作" fixed="right" align="right" width="120">
						<template #default="scope">
							<el-button-group>
								<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
							</el-button-group>
						</template>
					</el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>
	<fixed-details v-if="dialog.detailsSave" ref="detailsDialog" @closed="dialog.detailsSave=false"></fixed-details>
</template>
<script>

import FixedDetails from "@/views/office/fixed/fixedDetails";
import scSelectFilter from '@/components/scSelectFilter'
import selectUserDialog from "@/views/module/selectUserDialog";
export default {
	name: 'Fixed Approval Record',
	components: {
		FixedDetails,
		scSelectFilter,
		selectUserDialog
	},
	data() {
		return {
			apiObj: this.$API.office.fixed.getFixedAssetsAllocationOldList,
			selection: [],
			dialog: {
				fixedSort: false,
				save: false,
			},
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				}
			],
			showGrouploading: false,
			groupFilterText: '',
			fixedSortList:[],
			groupsProps: {
				label: "sortName",
				value: "sortId"
			},
			search: {
				deptId:'',
				date:'',
				keyword: null
			}
		}
	},
	watch: {
		groupFilterText(val) {
			this.$refs.fixedSort.filter(val);
		}
	},
	mounted() {
		this.getFixedAssetsSortGroup()
	},
	methods: {
		filterChange(data){
			this.search.date = data.date;
			this.$refs.table.upData(this.search)
		},
		//加载树数据
		async getFixedAssetsSortGroup() {
			this.showGrouploading = true;
			var res = await this.$API.office.fixed.getFixedAssetsSortTree.get();
			this.showGrouploading = false;
			this.fixedSortList = res.data;
		},
		//树过滤
		groupFilterNode(value, data) {
			if (!value) return true;
			return data.sortName.indexOf(value) !== -1;
		},
		//树点击事件
		groupClick(data) {
			this.search.sortId=data.sortId;
			this.$refs.table.reload(this.search)
		},
		//本地更新数据
		handleSuccess(data, mode) {
			this.$refs.table.refresh();
		},
		table_show(row, index) {
			this.dialog.detailsSave = true
			this.$nextTick(() => {
				this.$refs.detailsDialog.open().setData(row)
			})
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
	}
}
</script>
<style scoped>
.custom-tree-node {
	display: flex;
	flex: 1;
	align-items: center;
	justify-content: space-between;
	font-size: 14px;
	padding-right: 24px;
	height: 100%;
}

.custom-tree-node .code {
	font-size: 12px;
	color: #999;
}

.custom-tree-node .do {
	margin-left: 10px;
	display: none;
}

.custom-tree-node:hover .code {
	display: none;
}

.custom-tree-node:hover .do {
	margin-left: 10px;
	display: inline-block;
}
</style>
